//
//  HomePageUserNewsDateCell.m
//  ShowYork
//
//  Created by hxh on 2020/9/29.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "HomePageUserNewsDateCell.h"
#import <NSData+YYAdd.h>
@interface HomePageUserNewsDateCell ()
@property (nonatomic,strong)UILabel *dayLb;
@property (nonatomic,strong)UILabel *monthLb;
@end

@implementation HomePageUserNewsDateCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.backgroundColor = RGBA(16, 21, 34, 1);
    
    self.dayLb = [[UILabel alloc]init];
    self.dayLb.text = @"24";
    self.dayLb.textColor = UIColor.whiteColor;
    self.dayLb.font = [UIFont boldSystemFontOfSize:28];
    [self.contentView addSubview:self.dayLb];
    
    [self.dayLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-8);
        make.left.equalTo(self.contentView).offset(10);
    }];
    
    self.monthLb = [[UILabel alloc]init];
    self.monthLb.text = @"7月";
    self.monthLb.textColor = UIColor.whiteColor;
    self.monthLb.font = font(12);
    [self.contentView addSubview:self.monthLb];
    [self.monthLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dayLb.mas_right).offset(2);
        make.centerY.equalTo(self.dayLb);
    }];
}
- (void)setCreateDate:(NSNumber *)createDate{
    if (createDate.intValue == 0) {
        self.dayLb.text = @"";
        self.monthLb.text = @"";
    }else{
        NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:createDate.longValue/1000];
        
        if ([date isToday]) {
            self.dayLb.text = @"今天";
            self.monthLb.text = @"";
        }else if ([date isYesterday]){
            self.dayLb.text = @"昨天";
            self.monthLb.text = @"";
        }else{
            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
            formatter.dateFormat = @"MM";
            NSString *month = [formatter stringFromDate:date];
            formatter.dateFormat = @"dd";
            NSString *day = [formatter stringFromDate:date];
            self.dayLb.text = day;
            NSString *str = [month substringToIndex:1];
            
            if ([str isEqualToString:@"0"]) {
               month = [month stringByReplacingOccurrencesOfString:@"0" withString:@""];
            }
            self.monthLb.text = [NSString stringWithFormat:@"%@月",month];
        }
    }
}
@end
